//
//  BCRecommendVM.m
//  BananaChat
//
//  Created by 于洪东 on 2019/11/2.
//  Copyright © 2019 香蕉. All rights reserved.
//

#import "BCRecommendVM.h"
#import "BCRecommendListAPI.h"
#import "BCRecommendVideoModel.h"

@interface BCRecommendVM ()

@property (nonatomic,strong) NSMutableArray *listArray;

@end

@implementation BCRecommendVM

-(void)requestWithPageSize:(NSString *)pageSize gender:(NSString *)gender pageIndex:(NSString *)pageIndex{
    BCRecommendListAPI *api = [[BCRecommendListAPI alloc]initWithPageSize:pageSize gender:@"女" pageIndex:pageIndex];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        DEF_DEBUG(@"%@",request.responseJSONObject);
        NSMutableDictionary *datadic = request.responseJSONObject;
        
        NSMutableArray *dataArray = [BCRecommendVideoModel mj_objectArrayWithKeyValuesArray:datadic[@"data"]];
        
        if (pageIndex.intValue > 1) {
            [self.listArray addObjectsFromArray:dataArray];
        }else{
            self.listArray = dataArray;
        }
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(requestSuccess:data:)]) {
            [self.delegate requestSuccess:YES data:self.listArray];
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        DEF_DEBUG(@"%@",request.error);
        [MBProgressHUD showTipMessageInWindow:request.error.localizedFailureReason];
        if (self.delegate && [self.delegate respondsToSelector:@selector(requestSuccess:data:)]) {
            [self.delegate requestSuccess:NO data:@[].mutableCopy];
        }
    }];
}





-(NSMutableArray *)listArray{
    if (_listArray == nil) {
        _listArray = [NSMutableArray array];
    }
    return _listArray;
}

@end
